package com.jdls.tanhua.web;

import com.baomidou.mybatisplus.extension.api.R;
import com.jdls.tanhua.server.VideoServer;
import com.jdls.tanhua.vo.PageResult;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

/**
 * @author 嘉德罗斯
 * @date 2021/11/6
 */
@RequestMapping("/smallVideos")
@RestController
public class VideoWeb {

    @Autowired
    private VideoServer videoServer;

    @PostMapping
    //视频上传
    public ResponseEntity smallVideos(@RequestBody MultipartFile videoThumbnail,
                                      @RequestBody MultipartFile videoFile) throws IOException {
        videoServer.smallVideos(videoThumbnail,videoFile);


        return ResponseEntity.ok(null);
    }

    @GetMapping
    //查看视频
    public ResponseEntity find (@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult = videoServer.find(page,pagesize);

        return ResponseEntity.ok(pageResult);
    }

    @PostMapping("/{id}/like")
    //视频点赞
    public ResponseEntity like(@PathVariable ObjectId id){
        Integer like = videoServer.like(id);
        return ResponseEntity.ok(like);
    }

    @PostMapping("/{id}/dislike")
    //视频取消点赞
    public ResponseEntity dislike(@PathVariable ObjectId id){
        Integer like = videoServer.dislike(id);
        return ResponseEntity.ok(like);
    }

}
